package GreatBattleOfAircraft.obj;

import GreatBattleOfAircraft.Main;
import GreatBattleOfAircraft.utils.GameUtils;

import java.awt.*;

public class EnemyObj extends GameObj {
    public EnemyObj() {
        super();
    }

    public EnemyObj(Image img, int x, int y, int width, int height, double speed, Main frame) {
        super(img, x, y, width, height, speed, frame);
    }

    @Override
    public void painSelf(Graphics graphics) {
        super.painSelf(graphics);
        y+=speed;

        if (this.getRec().intersects(this.frame.planeObj.getRec())){
            Main.state = 3;
        }

        for (ShellObj shellObj: GameUtils.shellObjList){
            if (this.getRec().intersects(shellObj.getRec())){
                //爆炸效果
               BoomObj boomObj = new BoomObj(x-30,y,50,50);
               GameUtils.gameObjList.add(boomObj);
               //GameUtils.removeObjList.add(boomObj);未完成延时清理

                shellObj.setX(-100);
                shellObj.setY(100);
                this.x = -200;
                this.y = 200;
                GameUtils.removeObjList.add(shellObj);
                GameUtils.removeObjList.add(this);
                Main.score++;


            }
        }

        if (y>900){
            this.x = -1000;
            GameUtils.removeObjList.add(this);
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
